package net.lab1024.sa.admin.module.system.user.service;

import java.util.List;
import net.lab1024.sa.admin.module.system.user.dao.UserDao;
import net.lab1024.sa.admin.module.system.user.domain.form.UserQueryForm;
import net.lab1024.sa.admin.module.system.user.domain.vo.UserVO;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户表 Service
 *
 * @Author jabari
 * @Date 2023-06-12 14:10:13
 * @Copyright 51dev.cn
 */

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<UserVO> queryPage(UserQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<UserVO> list = userDao.queryPage(page, queryForm);
        PageResult<UserVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }


    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        userDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer userId) {
        if (null == userId){
            return ResponseDTO.ok();
        }

        userDao.updateDeleted(userId,true);
        return ResponseDTO.ok();
    }
}
